
import Constants from 'expo-constants'


export function getApiUrl() {
  const EXPO_PUBLIC_API_URL = 'http://localhost:3000/'

  // const apiUrl: any = process.env.EXPO_PUBLIC_API_URL
  const apiUrl = EXPO_PUBLIC_API_URL
  console.log('apiUrl', apiUrl)
  return replaceLocalhost(apiUrl)
}

export function getLocalhost() {
  const debuggerHost = Constants.expoConfig?.hostUri
  const localhost = debuggerHost?.split(':')[0] ?? 'localhost'
  return localhost
}

export function replaceLocalhost(address: string) {
  const PROTOCOL = 'http:'
  const localhostRegex = new RegExp(`${PROTOCOL}\/\/localhost:`, 'g')
  return address.replace(localhostRegex, () => `${PROTOCOL}//${getLocalhost()}:`)
}